From d477ca73536bc1b37ff7dd9e56d9163ce94679c9 Mon Sep 17 00:00:00 2001 From: robertl Date: Tue, 29 Oct 2002 03:07:40 +0000 Subject: [PATCH] Add undocumented (grrr) trkseg tags to gpx track handling. Misc cleanups for tracks and routes. --- gpsbabel/defs.h | 3 +++ gpsbabel/gpx.c | 67 +++++++++++++++++++++++++++++++++++++++++++++- gpsbabel/mapsend.c | 12 +++++---- gpsbabel/route.c | 16 ++++++----- 4 files changed, 85 insertions(+), 13 deletions(-) diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index 4405c384d..1710e10e6 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -152,9 +152,12 @@ typedef void (*ff_write) (void); void fprintdms(FILE *, const coord *, int); typedef void (*waypt_cb) (const waypoint *); +typedef void (*route_hdr)(const route_head *); +typedef void (*route_trl)(const route_head *); void waypt_add (waypoint *); void waypt_del (waypoint *); void waypt_disp_all(waypt_cb); +void route(route_hdr, route_trl, waypt_cb); unsigned int waypt_count(void); route_head *route_head_alloc(void); diff --git a/gpsbabel/gpx.c b/gpsbabel/gpx.c index 87338f63c..dacf8cebb 100644 --- a/gpsbabel/gpx.c +++ b/gpsbabel/gpx.c @@ -257,6 +257,7 @@ gpx_wr_deinit(void) { fclose(ofd); } + void gpx_read(void) { @@ -275,6 +276,26 @@ gpx_read(void) } } +/* + * + */ +static +void +gpx_write_time(const time_t timep) +{ + struct tm *tm = gmtime(&timep); + + fprintf(ofd, "\n", + tm->tm_year+1900, + tm->tm_mon+1, + tm->tm_mday, + tm->tm_hour, + tm->tm_min, + tm->tm_sec + ); + +} + static void gpx_waypt_pr(const waypoint *waypointp) { @@ -292,6 +313,9 @@ gpx_waypt_pr(const waypoint *waypointp) fprintf(ofd, "\n%f\n\n", waypointp->position.altitude.altitude_meters); } + if (waypointp->creation_time) { + gpx_write_time(waypointp->creation_time); + } if (waypointp->url) { fprintf(ofd, "%s\n", waypointp->url); } @@ -302,6 +326,43 @@ gpx_waypt_pr(const waypoint *waypointp) fprintf(ofd, "\n"); } +static void +gpx_track_hdr(route_head *rte) +{ + fprintf(ofd, "\n"); + if (rte->rte_name) { + fprintf(ofd, " \n"); + fprintf(ofd, " \n",rte->rte_name); + fprintf(ofd, " \n"); + } + fprintf(ofd, "\n"); +} + +static void +gpx_track_disp(const waypoint *waypointp) +{ + fprintf(ofd, "\n", + waypointp->position.latitude.degrees, + waypointp->position.longitude.degrees); + if (waypointp->creation_time) { + gpx_write_time(waypointp->creation_time); + } + fprintf(ofd, "\n"); +} + +static void +gpx_track_tlr(route_hdr *rte) +{ + fprintf(ofd, "\n"); + fprintf(ofd, "\n"); +} + +static +void gpx_track_pr() +{ + route_disp_all(gpx_track_hdr, gpx_track_tlr, gpx_track_disp); +} + void gpx_write(void) { @@ -314,7 +375,11 @@ gpx_write(void) fprintf(ofd, "xmlns=\"http://www.topografix.com/GPX/1/0\"\n"); fprintf(ofd, "xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd\">\n"); - waypt_disp_all(gpx_waypt_pr); + switch(global_opts.objective) { + case trkdata: gpx_track_pr(); + default: + case wptdata: waypt_disp_all(gpx_waypt_pr); + } fprintf(ofd, "\n"); } diff --git a/gpsbabel/mapsend.c b/gpsbabel/mapsend.c index 44126a36f..01df1b072 100644 --- a/gpsbabel/mapsend.c +++ b/gpsbabel/mapsend.c @@ -294,9 +294,9 @@ mapsend_read(void) mapsend_track_read(); break; case ms_type_log: - fatal(MYNAME ", GPS logs not supported.\n", type); + fatal(MYNAME ", GPS logs not supported.\n"); case ms_type_rgn: - fatal(MYNAME ", GPS regions not supported.\n", type); + fatal(MYNAME ", GPS regions not supported.\n"); default: fatal(MYNAME ", unknown file type %d\n", type); } @@ -343,7 +343,7 @@ n = 1; void mapsend_wpt_write(void) { - mapsend_hdr hdr = {13, "4D533330 MS", "30", ms_type_wpt}; + mapsend_hdr hdr = {13, "4D533330 MS", "30", ms_type_wpt, 0}; int wpt_count = waypt_count(); int n = 0; @@ -353,14 +353,16 @@ mapsend_wpt_write(void) waypt_disp_all(mapsend_waypt_pr); my_fwrite4(&n, mapsend_file_out); -/* TODO: Impelment routes here */ +/* TODO: Implement routes here */ } +#if LATER void mapsend_trk_write(void) { - mapsend_hdr hdr = {13, "4D533334 MS", "34", ms_type_track}; + mapsend_hdr hdr = {13, "4D533334 MS", "34", ms_type_track, 0}; } +#endif ff_vecs_t mapsend_vecs = { mapsend_rd_init, diff --git a/gpsbabel/route.c b/gpsbabel/route.c index 92c8f4a18..6a4edbcb1 100644 --- a/gpsbabel/route.c +++ b/gpsbabel/route.c @@ -53,24 +53,26 @@ route_add_wpt(route_head *rte, waypoint *wpt) } void -route_disp (route_head *rh) +route_disp (const route_head *rh, waypt_cb cb ) { queue *elem, *tmp; - printf("NEW ROUTE\n"); +// printf("NEW ROUTE\n"); QUEUE_FOR_EACH(&rh->waypoint_list, elem, tmp) { waypoint *waypointp; waypointp = (waypoint *) elem; - waypt_disp(waypointp); + (*cb)(waypointp); } } void -route_disp_all() +route_disp_all(route_hdr rh, route_trl rt, waypt_cb wc) { queue *elem, *tmp; QUEUE_FOR_EACH(&my_route_head, elem, tmp) { - route_head *rh; - rh = (route_head *) elem; - route_disp(rh); + const route_head *rhp; + rhp = (route_head *) elem; + (*rh)(rhp); + route_disp(rhp, wc); + (*rt)(rhp); } } -- 2.30.2